Purpose
The sort task sorts the elements of a given array and returns the sorted array. The default sort order is ascending (e.g., from A to Z or from 0 to 9). This task method changes the position of the elements in the original array.
Potential Use Case
The sort task can be used to sort arrays of numbers, strings and objects. You could use this task to arrange a list of names in alphabetical order, or a collection of dates in numerical order. For any outcome data that needs to be captured and sorted, you could potentially use sort .
Properties
Input and output properties are shown below.
| Input | Type | Description |
|---|---|---|
arr |
Array | Required. The array to be sorted. |
key |
String | Optional. For objects, a value used to set the sort order. |
limit |
Number | Optional. The number of records to return. |
reverse |
Boolean | Required. If true, the arr is sorted in reverse (descending) order. Default is false (ascending order). |
| Output | Type | Description |
|---|---|---|
response |
Array | The output of sorting the arr. |
Examples
Example 1
In this IAP example:
An array of incoming reference variables for
arrare statically set:[{"name": "cat"},{"name": "dog"},{"name": "hamster"},{"name": "ant"},{"name": "Lion"}].
Notice the name "Lion" is uppercase.The
keyparameter isname, and the recordlimitis 4.The
reverseparameter is false (default).
The sort order will be ascending in the
response, with "Lion" listed first in the sorted array since it begins with a capital (uppercase) letter.
Example 2
In this IAP example:
An array of incoming variables for
arrare statically set. The reference variables are:[{"car": "Audi"},{"car": "Volvo"},{"car": "Honda"},{"car": "BMW"}]. Notice all the initial letters in the names are uppercase.The
keyparameter iscar, and thelimitis left blank.The
reverseparameter is false (default).
The resulting sort order will be alphabetical (ascending order).

Example 3
In this IAP example:
An array of incoming variables for
arrare statically set. The reference variables are:["ant","bee","Cat","dog","Elephant"]. Notice the mix of lowercase and uppercase values.The
keyandlimitare left blank.The
reverseparameter is true.
The resulting sort order will be descending, with all the lowercase values listed in reverse alphabetical order followed by the uppercase values.
